import("//llvm/tools/binutils_symlinks.gni")
import("//llvm/utils/TableGen/tablegen.gni")
import("//llvm/utils/gn/build/symlink_or_copy.gni")

tablegen("BitcodeStripOpts") {
  visibility = [ ":llvm-objcopy" ]
  args = [ "-gen-opt-parser-defs" ]
}

tablegen("InstallNameToolOpts") {
  visibility = [ ":llvm-objcopy" ]
  args = [ "-gen-opt-parser-defs" ]
}

tablegen("ObjcopyOpts") {
  visibility = [ ":llvm-objcopy" ]
  args = [ "-gen-opt-parser-defs" ]
}

tablegen("StripOpts") {
  visibility = [ ":llvm-objcopy" ]
  args = [ "-gen-opt-parser-defs" ]
}

symlinks = [
  "llvm-bitcode-strip",
  "llvm-install-name-tool",
  "llvm-strip",
]
if (llvm_install_binutils_symlinks) {
  symlinks += [
    "objcopy",
    "strip",
  ]
}
foreach(target, symlinks) {
  symlink_or_copy(target) {
    deps = [ ":llvm-objcopy" ]
    source = "llvm-objcopy"
    output = "$root_out_dir/bin/$target"
  }
}

# //:llvm-objcopy depends on this symlink target, see comment in //BUILD.gn.
group("symlinks") {
  deps = []
  foreach(target, symlinks) {
    deps += [ ":$target" ]
  }
}

executable("llvm-objcopy") {
  deps = [
    ":BitcodeStripOpts",
    ":InstallNameToolOpts",
    ":ObjcopyOpts",
    ":StripOpts",
    "//llvm/lib/MC",
    "//llvm/lib/Object",
    "//llvm/lib/Option",
    "//llvm/lib/Support",
  ]
  include_dirs = [ "." ]
  sources = [
    "COFF/COFFObjcopy.cpp",
    "COFF/Object.cpp",
    "COFF/Reader.cpp",
    "COFF/Writer.cpp",
    "ConfigManager.cpp",
    "ELF/ELFObjcopy.cpp",
    "ELF/Object.cpp",
    "MachO/MachOLayoutBuilder.cpp",
    "MachO/MachOObjcopy.cpp",
    "MachO/MachOReader.cpp",
    "MachO/MachOWriter.cpp",
    "MachO/Object.cpp",
    "llvm-objcopy.cpp",
    "wasm/Object.cpp",
    "wasm/Reader.cpp",
    "wasm/WasmObjcopy.cpp",
    "wasm/Writer.cpp",
  ]
}
